#!/usr/bin/env node

/**
 * API一致性验证脚本
 * 验证HarmonyOS版本的SuotaLibLog是否与iOS版本API完全一致
 */

const fs = require('fs');
const path = require('path');

// 文件路径
const harmonyLogPath = './src/main/ets/components/plugin/SuotaLib/global/SuotaLibLog.ets';

console.log('🔍 验证SuotaLibLog API一致性...\n');

// 读取HarmonyOS版本文件
let harmonyContent = '';
try {
  harmonyContent = fs.readFileSync(harmonyLogPath, 'utf8');
  console.log('✅ 成功读取HarmonyOS版本文件');
} catch (error) {
  console.error('❌ 无法读取HarmonyOS版本文件:', error.message);
  process.exit(1);
}

// 验证项目列表
const verifications = [
  {
    name: 'iOS风格的宏定义常量',
    check: () => {
      const constants = [
        'SUOTA_LIB_LOG_SCAN_DEBUG',
        'SUOTA_LIB_LOG_SCAN_ERROR',
        'SUOTA_LIB_LOG_MANAGER',
        'SUOTA_LIB_LOG_PROTOCOL',
        'SUOTA_LIB_LOG_BLOCK',
        'SUOTA_LIB_LOG_CHUNK',
        'SUOTA_LIB_LOG_GATT_OPERATION',
        'SUOTA_LIB_LOG_SUOTA_FILE'
      ];
      return constants.every(constant => harmonyContent.includes(constant));
    }
  },
  {
    name: 'iOS风格的类属性getter方法',
    check: () => {
      const properties = [
        'public static get SCAN_DEBUG()',
        'public static get SCAN_ERROR()',
        'public static get MANAGER()',
        'public static get PROTOCOL()',
        'public static get BLOCK()',
        'public static get CHUNK()',
        'public static get GATT_OPERATION()',
        'public static get SUOTA_FILE()'
      ];
      return properties.every(prop => harmonyContent.includes(prop));
    }
  },
  {
    name: 'iOS风格的日志宏等效方法',
    check: () => {
      return harmonyContent.includes('public static SuotaLog(') &&
             harmonyContent.includes('public static SuotaLogOpt(');
    }
  },
  {
    name: '保留的具体日志方法',
    check: () => {
      const methods = [
        'scanDebug',
        'scanError',
        'manager',
        'protocol',
        'block',
        'chunk',
        'gattOperation',
        'suotaFile'
      ];
      return methods.every(method => harmonyContent.includes(`public static ${method}(`));
    }
  },
  {
    name: '正确的hilog导入',
    check: () => {
      return harmonyContent.includes("import { hilog } from '@kit.PerformanceAnalysisKit'");
    }
  }
];

// 执行验证
let allPassed = true;
verifications.forEach((verification, index) => {
  const passed = verification.check();
  const status = passed ? '✅' : '❌';
  console.log(`${status} ${index + 1}. ${verification.name}`);
  if (!passed) {
    allPassed = false;
  }
});

console.log('\n' + '='.repeat(50));
if (allPassed) {
  console.log('🎉 所有验证项目都通过！HarmonyOS版本与iOS版本API完全一致。');
  console.log('\n📋 API一致性总结:');
  console.log('   • 宏定义常量: ✅ 匹配iOS #define风格');
  console.log('   • 类属性: ✅ 匹配iOS @property风格');
  console.log('   • 日志宏: ✅ 提供SuotaLog和SuotaLogOpt等效方法');
  console.log('   • 具体方法: ✅ 保留所有原有功能方法');
  console.log('   • 平台适配: ✅ 使用HarmonyOS hilog API');
} else {
  console.log('❌ 部分验证项目未通过，请检查实现。');
  process.exit(1);
}